<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <title>【学习记录】python matplotlib 自学入门（随缘更新）.md | 蓝湖畔淅淅沥沥的雨</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="说明 - 2022-05-05 本篇博客为本人原创, 原发布于CSDN, 在搭建个人博客后使用爬虫批量爬取并挂到个人博客, 出于一些技术原因博客未能完全还原到初始版本(而且我懒得修改), 在观看体验上会有一些瑕疵 ,若有需求会发布重制版总结性新博客。发布时间统一定为1111年11月11日。钦此。  貌似基础 add_subplot 前两个参数表示把面板划分成怎样的形状（几行几列）第三个参数表示图">
<meta property="og:type" content="article">
<meta property="og:title" content="【学习记录】python matplotlib 自学入门（随缘更新）.md">
<meta property="og:url" content="http://example.com/1111/11/11/%E3%80%90%E5%AD%A6%E4%B9%A0%E8%AE%B0%E5%BD%95%E3%80%91python%20matplotlib%20%E8%87%AA%E5%AD%A6%E5%85%A5%E9%97%A8%EF%BC%88%E9%9A%8F%E7%BC%98%E6%9B%B4%E6%96%B0%EF%BC%89/index.html">
<meta property="og:site_name" content="蓝湖畔淅淅沥沥的雨">
<meta property="og:description" content="说明 - 2022-05-05 本篇博客为本人原创, 原发布于CSDN, 在搭建个人博客后使用爬虫批量爬取并挂到个人博客, 出于一些技术原因博客未能完全还原到初始版本(而且我懒得修改), 在观看体验上会有一些瑕疵 ,若有需求会发布重制版总结性新博客。发布时间统一定为1111年11月11日。钦此。  貌似基础 add_subplot 前两个参数表示把面板划分成怎样的形状（几行几列）第三个参数表示图">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="1111-11-11T03:06:11.000Z">
<meta property="article:modified_time" content="2022-05-06T08:17:54.982Z">
<meta property="article:author" content="StarsWhisper">
<meta property="article:tag" content="OldBlog(Before20220505)">
<meta property="article:tag" content="画图">
<meta property="article:tag" content="python库">
<meta name="twitter:card" content="summary">
  
    <link rel="alternate" href="/atom.xml" title="蓝湖畔淅淅沥沥的雨" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  
<link rel="stylesheet" href="/css/style.css">

  
<link rel="stylesheet" href="/plugin/bganimation/bg.css">

  

  <link href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.10.0/katex.min.css" rel="stylesheet" type="text/css">
<meta name="generator" content="Hexo 6.1.0"></head>

<body>
  <div id="container">
    <div id="wrap">
      <div class="outer">
        <div class="widget-wrap mobile-header">
  <h3 class="widget-title"></h3>
  <div class="widget">
    <img class="avatar" src="/images/avatar.png">
    <h2 class="author">StarsWhisper</h2>
    <h3 class="description"></h3>
    <div class="count-box">
      <a href="/archives"><div><strong>75</strong><br>文章</div></a>
      <a href="/categories"><div><strong>31</strong><br>分类</div></a>
      <a href="/tags"><div><strong>56</strong><br>标签</div></a>
    </div>
    <ul class="blog-link">
     
          <a href="/" title="Home">
            <li>主页</li>
          </a>
        
          <a href="/archives" title="Archives">
            <li>归档</li>
          </a>
        
          <a href="/categories" title="Categories">
            <li>分类</li>
          </a>
        
          <a href="/tags" title="Tags">
            <li>标签</li>
          </a>
        
          <a href="/knightabout" title="Knightabout">
            <li>关于</li>
          </a>
        
          <a href="/bridges" title="Bridges">
            <li>传送门</li>
          </a>
        
          <a href="/announcement" title="Announcement">
            <li>公告</li>
          </a>
        
    </ul>
  </div>
</div>

        <section id="main"><article id="post-【学习记录】python matplotlib 自学入门（随缘更新）" class="wow slideInRight article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/1111/11/11/%E3%80%90%E5%AD%A6%E4%B9%A0%E8%AE%B0%E5%BD%95%E3%80%91python%20matplotlib%20%E8%87%AA%E5%AD%A6%E5%85%A5%E9%97%A8%EF%BC%88%E9%9A%8F%E7%BC%98%E6%9B%B4%E6%96%B0%EF%BC%89/" class="article-date">
  <time class="post-time" datetime="1111-11-11T03:06:11.000Z" itemprop="datePublished">
    <span class="post-month">11月</span><br/>
    <span class="post-day">11</span>
  </time>
</a>
   
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      【学习记录】python matplotlib 自学入门（随缘更新）.md
    </h1>
  

        <div>
          
  <div class="article-category">
    <a class="article-category-link" href="/categories/%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86/">基础知识</a>,<a class="article-category-link" href="/categories/%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86/python/">python</a>,<a class="article-category-link" href="/categories/%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86/python/matplotlib/">matplotlib</a>
  </div>

          
              

          
        </div>
      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h2 id="说明-2022-05-05"><a class="markdownIt-Anchor" href="#说明-2022-05-05"></a> 说明 - 2022-05-05</h2>
<p>本篇博客为本人原创, 原发布于CSDN, 在搭建个人博客后使用爬虫批量爬取并挂到个人博客, 出于一些技术原因博客未能完全还原到初始版本(而且我懒得修改), 在观看体验上会有一些瑕疵 ,若有需求会发布重制版总结性新博客。发布时间统一定为1111年11月11日。钦此。</p>
<h2 id="貌似基础"><a class="markdownIt-Anchor" href="#貌似基础"></a> 貌似基础</h2>
<p>add_subplot 前两个参数表示把面板划分成怎样的形状（几行几列）第三个参数表示图在面板中的位置</p>
<p>​</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> matplotlib.pyplot <span class="keyword">as</span> plt</span><br><span class="line">fig =plt.figure()</span><br><span class="line">ax1 = fig.add_subplot(<span class="number">2</span>,<span class="number">2</span>,<span class="number">1</span>)</span><br><span class="line">ax2 = fig.add_subplot(<span class="number">2</span>,<span class="number">2</span>,<span class="number">2</span>)</span><br></pre></td></tr></table></figure>
<p>![在这里插入图片描述](<a target="_blank" rel="noopener" href="https://img-blog.csdnimg.cn/20210110161619319.png?x-oss-">https://img-blog.csdnimg.cn/20210110161619319.png?x-oss-</a><br />
process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dsZGNtenk=,size_16,color_FFFFFF,t_70#pic_center)</p>
<p>​</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">fig,axes = plt.subplots(nrows= <span class="number">3</span>,ncols= <span class="number">3</span>)</span><br><span class="line">axes[<span class="number">1</span>,<span class="number">1</span>].<span class="built_in">set</span>(title = <span class="string">&#x27;middle&#x27;</span>)</span><br><span class="line">axes[<span class="number">0</span>,<span class="number">2</span>].<span class="built_in">set</span>(title = <span class="string">&#x27;NE&#x27;</span>)</span><br></pre></td></tr></table></figure>
<p>![在这里插入图片描述](<a target="_blank" rel="noopener" href="https://img-blog.csdnimg.cn/20210110161720574.png?x-oss-">https://img-blog.csdnimg.cn/20210110161720574.png?x-oss-</a><br />
process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dsZGNtenk=,size_16,color_FFFFFF,t_70#pic_center)</p>
<h2 id="线貌似基础"><a class="markdownIt-Anchor" href="#线貌似基础"></a> 线+貌似基础</h2>
<p>画一条线</p>
<p>​</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">fig,ax = plt.subplots()</span><br><span class="line">x = np.linspace(<span class="number">0</span>,np.pi)</span><br><span class="line">y_sinx = np.sin(x)</span><br><span class="line">ax.plot(x,y_cosx,linewidth = <span class="number">1</span>, markersize = <span class="number">6</span>,color = <span class="string">&#x27;red&#x27;</span>,linestyle=<span class="string">&#x27;-.&#x27;</span>)</span><br><span class="line"><span class="comment">#图上的和这个不一样的写法，一个效果</span></span><br></pre></td></tr></table></figure>
<p>![在这里插入图片描述](<a target="_blank" rel="noopener" href="https://img-blog.csdnimg.cn/20210110163055151.png?x-oss-">https://img-blog.csdnimg.cn/20210110163055151.png?x-oss-</a><br />
process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dsZGNtenk=,size_16,color_FFFFFF,t_70#pic_center)<br />
加点盐</p>
<p>​</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">fig,ax = plt.subplots()</span><br><span class="line">x = np.linspace(<span class="number">0</span>,np.pi)</span><br><span class="line">y_sinx = np.sin(x)</span><br><span class="line">ax.plot(x,y_cosx,linewidth = <span class="number">1</span>, markersize = <span class="number">6</span>,color = <span class="string">&#x27;red&#x27;</span>,linestyle=<span class="string">&#x27;-.&#x27;</span>)</span><br><span class="line">ax.<span class="built_in">set</span>(title = <span class="string">&#x27;ABC&#x27;</span>,xlabel = <span class="string">&#x27;X QwQ&#x27;</span>,ylabel = <span class="string">&#x27;-Y---&#x27;</span>,xlim = [<span class="number">0</span>,<span class="number">5</span>],ylim = [-<span class="number">1.2</span>,<span class="number">1.2</span>])</span><br></pre></td></tr></table></figure>
<p>![在这里插入图片描述](<a target="_blank" rel="noopener" href="https://img-blog.csdnimg.cn/2021011016424414.png?x-oss-">https://img-blog.csdnimg.cn/2021011016424414.png?x-oss-</a><br />
process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dsZGNtenk=,size_16,color_FFFFFF,t_70#pic_center)</p>
<h4 id="填充两线之间的空间"><a class="markdownIt-Anchor" href="#填充两线之间的空间"></a> 填充两线之间的空间</h4>
<p>再加点盐 ： fill_between 填充两线之间的空间</p>
<p>​</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">fig,ax = plt.subplots()</span><br><span class="line">x = np.linspace(<span class="number">0</span>,np.pi)</span><br><span class="line">y_sinx = np.sin(x)</span><br><span class="line">y_cosx = np.cos(x)</span><br><span class="line">y_tanx = np.tan(x)</span><br><span class="line">ax.plot(x,y_cosx,linewidth = <span class="number">1</span>, markersize = <span class="number">6</span>,color = <span class="string">&#x27;red&#x27;</span>,linestyle=<span class="string">&#x27;-.&#x27;</span>)</span><br><span class="line">ax.<span class="built_in">set</span>(title = <span class="string">&#x27;ABC&#x27;</span>,xlabel = <span class="string">&#x27;X QwQ&#x27;</span>,ylabel = <span class="string">&#x27;-Y---&#x27;</span>,xlim = [<span class="number">0</span>,<span class="number">5</span>],ylim = [-<span class="number">1.2</span>,<span class="number">1.2</span>])</span><br><span class="line">ax.fill_between(x,y_cosx,y_sinx,color = <span class="string">&#x27;yellow&#x27;</span>)</span><br></pre></td></tr></table></figure>
<p>![在这里插入图片描述](<a target="_blank" rel="noopener" href="https://img-blog.csdnimg.cn/20210110164613966.png?x-oss-">https://img-blog.csdnimg.cn/20210110164613966.png?x-oss-</a><br />
process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dsZGNtenk=,size_16,color_FFFFFF,t_70#pic_center)</p>
<h4 id="加入网格线"><a class="markdownIt-Anchor" href="#加入网格线"></a> 加入网格线</h4>
<p>换一种写法 并加入网格线</p>
<p>​</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">fig,ax = plt.subplots()</span><br><span class="line">x = np.linspace(<span class="number">0</span>,np.pi)</span><br><span class="line">data = &#123;<span class="string">&#x27;x&#x27;</span> : x,</span><br><span class="line">       <span class="string">&#x27;sin&#x27;</span> : np.sin(x),</span><br><span class="line">       <span class="string">&#x27;cos&#x27;</span> : np.cos(x),</span><br><span class="line">       <span class="string">&#x27;tan&#x27;</span> : np.tan(x)&#125;</span><br><span class="line"></span><br><span class="line">ax.plot(<span class="string">&#x27;x&#x27;</span>,<span class="string">&#x27;cos&#x27;</span>,linewidth = <span class="number">1</span>, markersize = <span class="number">6</span>,color = <span class="string">&#x27;red&#x27;</span>,linestyle=<span class="string">&#x27;-.&#x27;</span>,data = data)</span><br><span class="line">ax.<span class="built_in">set</span>(title = <span class="string">&#x27;ABC&#x27;</span>,xlabel = <span class="string">&#x27;X QwQ&#x27;</span>,ylabel = <span class="string">&#x27;-Y---&#x27;</span>,xlim = [<span class="number">0</span>,<span class="number">5</span>],ylim = [-<span class="number">1.2</span>,<span class="number">1.2</span>])</span><br><span class="line">ax.fill_between(<span class="string">&#x27;x&#x27;</span>,<span class="string">&#x27;cos&#x27;</span>,<span class="string">&#x27;tan&#x27;</span>,color = <span class="string">&#x27;yellow&#x27;</span>,data = data)</span><br><span class="line">ax.grid()</span><br></pre></td></tr></table></figure>
<p>![在这里插入图片描述](<a target="_blank" rel="noopener" href="https://img-blog.csdnimg.cn/20210110185516287.png?x-oss-">https://img-blog.csdnimg.cn/20210110185516287.png?x-oss-</a><br />
process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dsZGNtenk=,size_16,color_FFFFFF,t_70#pic_center)</p>
<h2 id="散点图"><a class="markdownIt-Anchor" href="#散点图"></a> 散点图</h2>
<p>参数c同color表示颜色 s表示大小</p>
<p>​</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">x = np.arange(<span class="number">6</span>)</span><br><span class="line">y = x*<span class="number">3</span>%<span class="number">8</span></span><br><span class="line">plt.scatter(x,y,marker = <span class="string">&#x27;3&#x27;</span>,color = [<span class="string">&#x27;blue&#x27;</span>,<span class="string">&#x27;green&#x27;</span>,<span class="string">&#x27;blue&#x27;</span>,<span class="string">&#x27;green&#x27;</span>,<span class="string">&#x27;blue&#x27;</span>,<span class="string">&#x27;green&#x27;</span>,], s = <span class="number">600</span>)</span><br></pre></td></tr></table></figure>
<p>![在这里插入图片描述](<a target="_blank" rel="noopener" href="https://img-blog.csdnimg.cn/20210110170857320.png?x-oss-">https://img-blog.csdnimg.cn/20210110170857320.png?x-oss-</a><br />
process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dsZGNtenk=,size_16,color_FFFFFF,t_70#pic_center)</p>
<p>​</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">x = np.arange(<span class="number">10</span>)</span><br><span class="line">y = x*<span class="number">3</span>%<span class="number">13</span></span><br><span class="line">plt.scatter(x,y,marker = <span class="string">&#x27;*&#x27;</span>,c = np.random.rand(<span class="number">10</span>),s = (np.random.rand(<span class="number">10</span>)*<span class="number">30</span>)**<span class="number">2</span>)</span><br></pre></td></tr></table></figure>
<p>![在这里插入图片描述](<a target="_blank" rel="noopener" href="https://img-blog.csdnimg.cn/2021011017090355.png?x-oss-">https://img-blog.csdnimg.cn/2021011017090355.png?x-oss-</a><br />
process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dsZGNtenk=,size_16,color_FFFFFF,t_70#pic_center)</p>
<h2 id="条形图"><a class="markdownIt-Anchor" href="#条形图"></a> 条形图</h2>
<h4 id="调整画布大小"><a class="markdownIt-Anchor" href="#调整画布大小"></a> 调整画布大小</h4>
<p>参数figsize调整画布大小</p>
<p>​</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">x = np.arange(<span class="number">10</span>)</span><br><span class="line">y = np.random.randint(<span class="number">0</span>,<span class="number">10</span>,<span class="number">10</span>)</span><br><span class="line">fig,axes = plt.subplots(ncols = <span class="number">2</span>,figsize = (<span class="number">20</span>,<span class="number">6</span>))</span><br><span class="line">axes[<span class="number">0</span>].bar(x,y,color = <span class="string">&#x27;red&#x27;</span>)</span><br><span class="line">axes[<span class="number">0</span>].<span class="built_in">set</span>(title = <span class="string">&#x27;E GAY WOLY GIAO~GIAO&#x27;</span>,xlabel = <span class="string">&#x27;q&#x27;</span>,ylim = [-<span class="number">2</span>,<span class="number">10</span>])</span><br><span class="line">axes[<span class="number">1</span>].barh(x,y,color = <span class="string">&#x27;lightgreen&#x27;</span>)</span><br><span class="line">axes[<span class="number">1</span>].<span class="built_in">set</span>(ylim = [-<span class="number">3</span>,<span class="number">15</span>])</span><br></pre></td></tr></table></figure>
<p>![在这里插入图片描述](<a target="_blank" rel="noopener" href="https://img-blog.csdnimg.cn/20210110173351106.png?x-oss-">https://img-blog.csdnimg.cn/20210110173351106.png?x-oss-</a><br />
process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dsZGNtenk=,size_16,color_FFFFFF,t_70#pic_center)</p>
<h4 id="画直线"><a class="markdownIt-Anchor" href="#画直线"></a> 画直线</h4>
<p>加一道线</p>
<p>​</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">x = np.arange(<span class="number">10</span>)</span><br><span class="line">y = np.random.randint(<span class="number">0</span>,<span class="number">10</span>,<span class="number">10</span>)</span><br><span class="line">fig,axes = plt.subplots(ncols = <span class="number">2</span>,figsize = (<span class="number">20</span>,<span class="number">6</span>))</span><br><span class="line">axes[<span class="number">0</span>].bar(x,y,color = <span class="string">&#x27;red&#x27;</span>)</span><br><span class="line">axes[<span class="number">0</span>].<span class="built_in">set</span>(title = <span class="string">&#x27;E GAY WOLY GIAO~GIAO&#x27;</span>,xlabel = <span class="string">&#x27;q&#x27;</span>,ylim = [-<span class="number">2</span>,<span class="number">10</span>])</span><br><span class="line">axes[<span class="number">1</span>].barh(x,y,color = <span class="string">&#x27;lightgreen&#x27;</span>)</span><br><span class="line">axes[<span class="number">1</span>].<span class="built_in">set</span>(ylim = [-<span class="number">3</span>,<span class="number">15</span>])</span><br><span class="line">axes[<span class="number">0</span>].axhline(<span class="number">0</span>,color = <span class="string">&#x27;blue&#x27;</span>,linewidth = <span class="number">6</span>)</span><br><span class="line">axes[<span class="number">1</span>].axvline(<span class="number">2</span>,color = <span class="string">&#x27;lightgrey&#x27;</span>,linewidth = <span class="number">3</span>)</span><br></pre></td></tr></table></figure>
<p>![在这里插入图片描述](<a target="_blank" rel="noopener" href="https://img-blog.csdnimg.cn/20210110173710153.png?x-oss-">https://img-blog.csdnimg.cn/20210110173710153.png?x-oss-</a><br />
process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dsZGNtenk=,size_16,color_FFFFFF,t_70#pic_center)<br />
有负数的情况<br />
![在这里插入图片描述](<a target="_blank" rel="noopener" href="https://img-blog.csdnimg.cn/20210110173936447.png?x-oss-">https://img-blog.csdnimg.cn/20210110173936447.png?x-oss-</a><br />
process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dsZGNtenk=,size_16,color_FFFFFF,t_70#pic_center)</p>
<h2 id="饼图"><a class="markdownIt-Anchor" href="#饼图"></a> 饼图</h2>
<p>​</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">names = [<span class="string">&#x27;AA&#x27;</span>,<span class="string">&#x27;BB&#x27;</span>,<span class="string">&#x27;CC&#x27;</span>,<span class="string">&#x27;DD&#x27;</span>,<span class="string">&#x27;EE&#x27;</span>]</span><br><span class="line">weights = [<span class="number">200</span>,<span class="number">300</span>,<span class="number">500</span>,<span class="number">159</span>,<span class="number">66</span>]</span><br><span class="line">plt.pie(weights,labels = names)</span><br><span class="line"><span class="keyword">pass</span></span><br></pre></td></tr></table></figure>
<p>![在这里插入图片描述](<a target="_blank" rel="noopener" href="https://img-blog.csdnimg.cn/20210110174927927.png?x-oss-">https://img-blog.csdnimg.cn/20210110174927927.png?x-oss-</a><br />
process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dsZGNtenk=,size_16,color_FFFFFF,t_70#pic_center)</p>
<p>​</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">names = [<span class="string">&#x27;AA&#x27;</span>,<span class="string">&#x27;BB&#x27;</span>,<span class="string">&#x27;CC&#x27;</span>,<span class="string">&#x27;DD&#x27;</span>,<span class="string">&#x27;EE&#x27;</span>]</span><br><span class="line">weights = [<span class="number">200</span>,<span class="number">300</span>,<span class="number">500</span>,<span class="number">159</span>,<span class="number">66</span>]</span><br><span class="line">colors = [<span class="string">&#x27;lightblue&#x27;</span>,<span class="string">&#x27;lightgreen&#x27;</span>,<span class="string">&#x27;red&#x27;</span>,<span class="string">&#x27;green&#x27;</span>,<span class="string">&#x27;grey&#x27;</span>]</span><br><span class="line">plt.pie(weights,labels = names,</span><br><span class="line">        explode = [<span class="number">0</span>,<span class="number">0</span>,<span class="number">0.1</span>,<span class="number">0.075</span>,<span class="number">0</span>], <span class="comment">#每一块离开饼中心的距离</span></span><br><span class="line">        colors = colors,             <span class="comment">#颜色</span></span><br><span class="line">        shadow = <span class="literal">True</span>,               <span class="comment">#阴影</span></span><br><span class="line">        autopct = <span class="string">&#x27;%.4f%%&#x27;</span>,          <span class="comment">#显示百分比（格式化输出）</span></span><br><span class="line">        startangle = -<span class="number">30</span>,             <span class="comment">#绘制角度 （旋转）</span></span><br><span class="line">        counterclock = <span class="literal">False</span>,        <span class="comment">#指针方向 默认=ture为逆时针  False为顺时针</span></span><br><span class="line">        radius = <span class="number">1.3</span>,               <span class="comment">#饼图半径</span></span><br><span class="line">        labeldistance = <span class="number">1.3</span>,         <span class="comment">#label的位置 （与半径的比例）</span></span><br><span class="line">        pctdistance = <span class="number">0.3</span>,           <span class="comment">#显示百分比的文本的位置（与半径的比例）</span></span><br><span class="line">        textprops = <span class="literal">None</span>,            <span class="comment">#文本格式</span></span><br><span class="line">        </span><br><span class="line">       )</span><br><span class="line">plt.axis(<span class="string">&#x27;equal&#x27;</span>) <span class="comment">#显示为正圆</span></span><br><span class="line">plt.legend(loc = <span class="string">&#x27;lower left&#x27;</span>)      <span class="comment">#显示图例</span></span><br><span class="line"><span class="keyword">pass</span></span><br></pre></td></tr></table></figure>
<p>![在这里插入图片描述](<a target="_blank" rel="noopener" href="https://img-blog.csdnimg.cn/20210110181032977.png?x-oss-">https://img-blog.csdnimg.cn/20210110181032977.png?x-oss-</a><br />
process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dsZGNtenk=,size_16,color_FFFFFF,t_70#pic_center)<br />
所有图例位置名称</p>
<blockquote>
<p>:18: MatplotlibDeprecationWarning: Unrecognized location ‘lower dleft’.<br />
Falling back on ‘best’; valid locations are<br />
best<br />
upper right<br />
upper left<br />
lower left<br />
lower right<br />
right<br />
center left<br />
center right<br />
lower center<br />
upper center<br />
center<br />
This will raise an exception in 3.3.</p>
</blockquote>
<p>plt.savefig( ) 保存</p>
<h6 id="条形图饼图组合-bar-of-pie"><a class="markdownIt-Anchor" href="#条形图饼图组合-bar-of-pie"></a> 条形图+饼图组合 Bar of pie</h6>
<p>​</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> matplotlib.patches <span class="keyword">import</span> ConnectionPatch</span><br><span class="line"></span><br><span class="line">fig,[ax0,ax1] = plt.subplots(ncols = <span class="number">2</span>,figsize = [<span class="number">12</span>,<span class="number">6</span>])</span><br><span class="line"></span><br><span class="line"><span class="comment">#画饼</span></span><br><span class="line">names = [<span class="string">&#x27;AA&#x27;</span>,<span class="string">&#x27;BB&#x27;</span>,<span class="string">&#x27;CC&#x27;</span>,<span class="string">&#x27;DD&#x27;</span>,<span class="string">&#x27;EE&#x27;</span>]</span><br><span class="line">weights = [<span class="number">200</span>,<span class="number">300</span>,<span class="number">500</span>,<span class="number">159</span>,<span class="number">66</span>]</span><br><span class="line">colors = [<span class="string">&#x27;lightblue&#x27;</span>,<span class="string">&#x27;lightgreen&#x27;</span>,<span class="string">&#x27;red&#x27;</span>,<span class="string">&#x27;green&#x27;</span>,<span class="string">&#x27;grey&#x27;</span>]</span><br><span class="line">ax0.pie(weights,</span><br><span class="line">        labels = <span class="literal">None</span>,</span><br><span class="line">        explode = [<span class="number">0</span>,<span class="number">0.1</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>], <span class="comment">#每一块离开饼中心的距离</span></span><br><span class="line">        colors = colors,             <span class="comment">#颜色</span></span><br><span class="line">        shadow = <span class="literal">True</span>,               <span class="comment">#阴影</span></span><br><span class="line">        autopct = <span class="string">&#x27;%.4f%%&#x27;</span>,          <span class="comment">#显示百分比（格式化输出）</span></span><br><span class="line">        startangle = <span class="number">100</span>,             <span class="comment">#绘制角度 （旋转）</span></span><br><span class="line">        counterclock = <span class="literal">False</span>,        <span class="comment">#指针方向 默认=ture为逆时针  False为顺时针</span></span><br><span class="line">        radius = <span class="number">1</span>,               <span class="comment">#饼图半径</span></span><br><span class="line">        labeldistance = <span class="number">0.85</span>,         <span class="comment">#label的位置 （与半径的比例）</span></span><br><span class="line">        pctdistance = <span class="number">0.65</span>,           <span class="comment">#显示百分比的文本的位置（与半径的比例）</span></span><br><span class="line">        textprops = <span class="literal">None</span>,            <span class="comment">#文本格式</span></span><br><span class="line">        </span><br><span class="line">       )</span><br><span class="line">ax0.axis(<span class="string">&#x27;equal&#x27;</span>) <span class="comment">#显示为正圆</span></span><br><span class="line">ax0.legend(names,loc = <span class="string">&#x27;upper left&#x27;</span>)      <span class="comment">#显示图例</span></span><br><span class="line">ax0.<span class="built_in">set</span>(title = <span class="string">&#x27;Big&#x27;</span>)</span><br></pre></td></tr></table></figure>
<p>​<br />
​</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#画柱</span></span><br><span class="line">rates = [<span class="number">0.33</span>,<span class="number">0.56</span>,<span class="number">0.07</span>,<span class="number">0.04</span>]</span><br><span class="line">posX = <span class="number">0</span></span><br><span class="line">floor = <span class="number">0</span></span><br><span class="line">width = <span class="number">0.2</span></span><br></pre></td></tr></table></figure>
<p>​</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="built_in">len</span>(rates)):</span><br><span class="line">    height = rates[i]</span><br><span class="line">    ax1.bar(posX,height,width,bottom = floor)</span><br><span class="line">    posY = ax1.patches[i].get_height() / <span class="number">2</span> + floor</span><br><span class="line">    ax1.text(posX,posY,<span class="string">&#x27;%d%%&#x27;</span> % (rates[i]*<span class="number">100</span>), ha = <span class="string">&#x27;center&#x27;</span>)</span><br><span class="line">    floor += ax1.patches[i].get_height()</span><br><span class="line"></span><br><span class="line">ax1.<span class="built_in">set</span>(ylim = [<span class="number">0</span>,<span class="number">1</span>],xlim = [-<span class="number">0.5</span>,<span class="number">2</span>],title = <span class="string">&#x27;Small&#x27;</span>)</span><br><span class="line">ax1.axis(<span class="string">&#x27;off&#x27;</span>)                                  <span class="comment">#边框消失</span></span><br><span class="line">ax1.legend([<span class="string">&#x27;B1&#x27;</span>,<span class="string">&#x27;B2&#x27;</span>,<span class="string">&#x27;B3&#x27;</span>,<span class="string">&#x27;B4&#x27;</span>],loc = <span class="string">&#x27;center&#x27;</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment">#划线</span></span><br><span class="line">top = <span class="number">1</span></span><br><span class="line">startangle = <span class="number">0</span>    <span class="comment">#曾经多此一举加上了起始角度</span></span><br><span class="line">center, r = ax0.patches[<span class="number">2</span>].center, ax0.patches[<span class="number">2</span>].r</span><br><span class="line">theta1,theta2 = ax0.patches[<span class="number">2</span>].theta1+startangle,ax0.patches[<span class="number">2</span>].theta2+startangle</span><br><span class="line"></span><br><span class="line">xb,yb = np.cos(np.pi / <span class="number">180</span> * theta2) *r + center[<span class="number">0</span>], np.sin(np.pi / <span class="number">180</span> * theta2) *r + center[<span class="number">1</span>]</span><br><span class="line">con = ConnectionPatch(xyA = (-width/<span class="number">2</span>,top), coordsA = ax1.transData, xyB = (xb,yb), coordsB = ax0.transData)</span><br><span class="line">ax1.add_artist(con)</span><br><span class="line"></span><br><span class="line">xb,yb = np.cos(np.pi / <span class="number">180</span> * theta1) *r + center[<span class="number">0</span>], np.sin(np.pi / <span class="number">180</span> * theta1) *r + center[<span class="number">1</span>]</span><br><span class="line">con = ConnectionPatch(xyA = (-width/<span class="number">2</span>,<span class="number">0</span>), coordsA = ax1.transData, xyB = (xb,yb), coordsB = ax0.transData)</span><br><span class="line">ax1.add_artist(con)</span><br><span class="line">con.set_color([<span class="number">1</span>,<span class="number">0.5</span>,<span class="number">0</span>])</span><br><span class="line">con.set_linewidth(<span class="number">5</span>)</span><br><span class="line"></span><br><span class="line"><span class="keyword">pass</span></span><br></pre></td></tr></table></figure>
<p>![在这里插入图片描述](<a target="_blank" rel="noopener" href="https://img-blog.csdnimg.cn/202101102053298.png?x-oss-">https://img-blog.csdnimg.cn/202101102053298.png?x-oss-</a><br />
process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dsZGNtenk=,size_16,color_FFFFFF,t_70#pic_center)</p>
<h2 id="嵌套环形图条形图组合-实例"><a class="markdownIt-Anchor" href="#嵌套环形图条形图组合-实例"></a> 嵌套环形图+条形图组合 实例</h2>
<p>太急于实现写的乱起八糟，以后可以复习思路<br />
2021年2月9号东八区凌晨画完的，于同日中午放上来</p>
<p>​</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> matplotlib.patches <span class="keyword">import</span> ConnectionPatch</span><br><span class="line">angle = <span class="number">120</span></span><br><span class="line">fig,[ax0,ax1,ax2] = plt.subplots(ncols = <span class="number">3</span>,figsize = [<span class="number">27</span>,<span class="number">9</span>])</span><br><span class="line">names = [<span class="string">&#x27;Index&#x27;</span>,<span class="string">&#x27;Finance&#x27;</span>,<span class="string">&#x27;Resources&#x27;</span>,<span class="string">&#x27;Policy&#x27;</span>,<span class="string">&#x27;Thought&#x27;</span>]</span><br><span class="line">weights = [<span class="number">0.2</span>,<span class="number">0.16</span>,<span class="number">0.12</span>,<span class="number">0.28</span>,<span class="number">0.24</span>]</span><br><span class="line">cc = [<span class="string">&#x27;yellow&#x27;</span>,<span class="string">&#x27;#ff8040&#x27;</span>,<span class="string">&#x27;lightgreen&#x27;</span>,<span class="string">&#x27;#00ffff&#x27;</span>,<span class="string">&#x27;#b15bff&#x27;</span>]</span><br><span class="line">cc.extend([<span class="string">&#x27;red&#x27;</span>]*<span class="number">4</span>)</span><br><span class="line"></span><br><span class="line">ax1.pie(weights,labels = names,</span><br><span class="line">        explode = [<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>], <span class="comment">#每一块离开饼中心的距离</span></span><br><span class="line">        colors = cc,             <span class="comment">#颜色</span></span><br><span class="line">        shadow = <span class="literal">False</span>,               <span class="comment">#阴影</span></span><br><span class="line">        autopct = <span class="string">&#x27;%.2f%%&#x27;</span>,          <span class="comment">#显示百分比（格式化输出）</span></span><br><span class="line">        startangle = angle,             <span class="comment">#绘制角度 （旋转）</span></span><br><span class="line">        counterclock = <span class="literal">False</span>,        <span class="comment">#指针方向 默认=ture为逆时针  False为顺时针</span></span><br><span class="line">        radius = <span class="number">0.75</span>,               <span class="comment">#饼图半径</span></span><br><span class="line">        labeldistance = <span class="number">0.75</span>,         <span class="comment">#label的位置 （与半径的比例）</span></span><br><span class="line">        pctdistance = <span class="number">0.6</span>,           <span class="comment">#显示百分比的文本的位置（与半径的比例）</span></span><br><span class="line">        textprops = <span class="literal">None</span>,            <span class="comment">#文本格式</span></span><br><span class="line">        wedgeprops = <span class="built_in">dict</span>(width = <span class="number">0.2</span>,edgecolor = <span class="string">&#x27;white&#x27;</span>)</span><br><span class="line">       )</span><br><span class="line">ax1.legend(loc = <span class="string">&#x27;center&#x27;</span>)</span><br><span class="line"><span class="comment">#color = [&#x27;red&#x27;] *23</span></span><br><span class="line">color = [<span class="string">&#x27;#ffffaa&#x27;</span>,<span class="string">&#x27;#ffff6f&#x27;</span>,<span class="string">&#x27;#f9f900&#x27;</span>,<span class="string">&#x27;#d9b300&#x27;</span>]</span><br><span class="line">color.extend([<span class="string">&#x27;#ffbd9d&#x27;</span>,<span class="string">&#x27;#ff8f59&#x27;</span>,<span class="string">&#x27;#ff5809&#x27;</span>,<span class="string">&#x27;#ff5151&#x27;</span>,<span class="string">&#x27;#ea0000&#x27;</span>,<span class="string">&#x27;#ff5809&#x27;</span>])</span><br><span class="line">color.extend([<span class="string">&#x27;#d7ffee&#x27;</span>,<span class="string">&#x27;#96fed1&#x27;</span>,<span class="string">&#x27;#4efeb3&#x27;</span>,<span class="string">&#x27;#02f78e&#x27;</span>,<span class="string">&#x27;#28ff28&#x27;</span>,<span class="string">&#x27;#00db00&#x27;</span>,<span class="string">&#x27;#007500&#x27;</span>])</span><br><span class="line">color.extend([<span class="string">&#x27;#bbffff&#x27;</span>,<span class="string">&#x27;#80ffff&#x27;</span>,<span class="string">&#x27;#00e3e3&#x27;</span>,<span class="string">&#x27;#00aeae&#x27;</span>])</span><br><span class="line">color.extend([<span class="string">&#x27;#ca8eef&#x27;</span>,<span class="string">&#x27;#d200d2&#x27;</span>])</span><br><span class="line">small_n = [<span class="string">&#x27;&#x27;</span>,<span class="string">&#x27;&#x27;</span>,<span class="string">&#x27;&#x27;</span>,<span class="string">&#x27;&#x27;</span>,<span class="string">&#x27;&#x27;</span>,<span class="string">&#x27;&#x27;</span>,<span class="string">&#x27;&#x27;</span>,<span class="string">&#x27;&#x27;</span>,<span class="string">&#x27;&#x27;</span>,<span class="string">&#x27;&#x27;</span>,<span class="string">&#x27;&#x27;</span>,<span class="string">&#x27;&#x27;</span>,<span class="string">&#x27;&#x27;</span>,<span class="string">&#x27;&#x27;</span>,<span class="string">&#x27;&#x27;</span>,<span class="string">&#x27;&#x27;</span>,<span class="string">&#x27;&#x27;</span>,<span class="string">&#x27;&#x27;</span>,<span class="string">&#x27;&#x27;</span>,<span class="string">&#x27;&#x27;</span>,<span class="string">&#x27;&#x27;</span>,<span class="string">&#x27;&#x27;</span>,<span class="string">&#x27;&#x27;</span>]</span><br><span class="line">small = [<span class="number">6.667</span>,<span class="number">6.667</span>,<span class="number">4.444</span>,<span class="number">2.222</span>,<span class="number">1.333</span>,<span class="number">3.111</span>,<span class="number">2.667</span>,<span class="number">2.222</span>,<span class="number">3.556</span>,<span class="number">3.111</span>,<span class="number">2.043</span>,<span class="number">2.043</span>,<span class="number">2.809</span>,<span class="number">1.787</span>,<span class="number">1.021</span>,<span class="number">1.021</span>,<span class="number">1.277</span>,<span class="number">9.882</span>,<span class="number">6.588</span>,<span class="number">8.235</span>,<span class="number">3.294</span>,<span class="number">6</span>,<span class="number">18</span>]</span><br><span class="line">ax1.pie(small,</span><br><span class="line">        labels = small_n,</span><br><span class="line">        explode = [<span class="number">0</span>]*<span class="number">23</span>, <span class="comment">#每一块离开饼中心的距离</span></span><br><span class="line">        colors = color,             <span class="comment">#颜色</span></span><br><span class="line">        shadow = <span class="literal">False</span>,               <span class="comment">#阴影</span></span><br><span class="line">        autopct = <span class="string">&#x27;%.2f%%&#x27;</span>,          <span class="comment">#显示百分比（格式化输出）</span></span><br><span class="line">        startangle = angle,             <span class="comment">#绘制角度 （旋转）</span></span><br><span class="line">        counterclock = <span class="literal">False</span>,        <span class="comment">#指针方向 默认=ture为逆时针  False为顺时针</span></span><br><span class="line">        radius = <span class="number">1</span>,               <span class="comment">#饼图半径</span></span><br><span class="line">        labeldistance = <span class="number">0.85</span>,         <span class="comment">#label的位置 （与半径的比例）</span></span><br><span class="line">        pctdistance = <span class="number">1.1</span>,           <span class="comment">#显示百分比的文本的位置（与半径的比例）</span></span><br><span class="line">        textprops = <span class="literal">None</span>,            <span class="comment">#文本格式</span></span><br><span class="line">        wedgeprops = <span class="built_in">dict</span>(width = <span class="number">0.22</span>,edgecolor = <span class="string">&#x27;white&#x27;</span>)</span><br><span class="line">       )</span><br><span class="line">ax1.axis(<span class="string">&#x27;equal&#x27;</span>) <span class="comment">#显示为正圆</span></span><br></pre></td></tr></table></figure>
<p>​</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#画柱</span></span><br><span class="line">lll = [<span class="number">1.333</span>,<span class="number">3.111</span>,<span class="number">2.667</span>,<span class="number">2.222</span>,<span class="number">3.556</span>,<span class="number">3.111</span>,<span class="number">2.043</span>,<span class="number">2.043</span>,<span class="number">2.809</span>,<span class="number">1.787</span>,<span class="number">1.021</span>,<span class="number">1.021</span>,<span class="number">1.277</span>]</span><br><span class="line">colorssss = [<span class="string">&#x27;#ffbd9d&#x27;</span>,<span class="string">&#x27;#ff8f59&#x27;</span>,<span class="string">&#x27;#ff5809&#x27;</span>,<span class="string">&#x27;#ff5151&#x27;</span>,<span class="string">&#x27;#ea0000&#x27;</span>,<span class="string">&#x27;#ff5809&#x27;</span>,<span class="string">&#x27;#d7ffee&#x27;</span></span><br><span class="line">             ,<span class="string">&#x27;#96fed1&#x27;</span>,<span class="string">&#x27;#4efeb3&#x27;</span>,<span class="string">&#x27;#02f78e&#x27;</span>,<span class="string">&#x27;#28ff28&#x27;</span>,<span class="string">&#x27;#00db00&#x27;</span>,<span class="string">&#x27;#007500&#x27;</span>]</span><br><span class="line">colorssss.reverse()</span><br><span class="line">lll.reverse()</span><br><span class="line">ttt = [<span class="string">&#x27;Proportion of tuition fees in total family income&#x27;</span></span><br><span class="line">       ,<span class="string">&#x27;Pass rate of economic aid&#x27;</span></span><br><span class="line">       ,<span class="string">&#x27;Average amount of undergraduate assistance&#x27;</span></span><br><span class="line">       ,<span class="string">&#x27;Proportion of aid amount to tuition fee&#x27;</span></span><br><span class="line">       ,<span class="string">&#x27;Proportion of education funds in the budget&#x27;</span></span><br><span class="line">       ,<span class="string">&#x27;Education funds&#x27;</span></span><br><span class="line">       ,<span class="string">&#x27;Difficulty of curriculum design&#x27;</span></span><br><span class="line">       ,<span class="string">&#x27;Professional discipline depth&#x27;</span></span><br><span class="line">       ,<span class="string">&#x27;Rationality of teaching plan&#x27;</span></span><br><span class="line">       ,<span class="string">&#x27;Teaching Staff level&#x27;</span></span><br><span class="line">       ,<span class="string">&#x27;Scholarships and grants&#x27;</span></span><br><span class="line">       ,<span class="string">&#x27;Number of teaching staff&#x27;</span></span><br><span class="line">       ,<span class="string">&#x27;Average salary of teaching staff&#x27;</span>]</span><br><span class="line">tttr = ttt.copy()</span><br><span class="line">tttr.reverse()</span><br><span class="line">rates = (np.array(lll)/<span class="built_in">sum</span>(lll)).tolist()</span><br><span class="line">posX = -<span class="number">0.1</span></span><br><span class="line">floor = <span class="number">0</span></span><br><span class="line">width = <span class="number">0.2</span></span><br></pre></td></tr></table></figure>
<p>​</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="built_in">len</span>(rates)):</span><br><span class="line">    height = rates[i]</span><br><span class="line">    ax2.bar(posX,height,width,bottom = floor,color = colorssss[i])</span><br><span class="line">    posY = ax2.patches[i].get_height() / <span class="number">2</span> + floor</span><br><span class="line">    ax2.text(posX-<span class="number">0.07</span>,posY,<span class="string">&#x27;%.2f%%    &#x27;</span> % (lll[i])+ tttr[i], ha = <span class="string">&#x27;left&#x27;</span>)</span><br><span class="line">    floor += ax2.patches[i].get_height()</span><br><span class="line"></span><br><span class="line">ax2.<span class="built_in">set</span>(ylim = [<span class="number">0</span>,<span class="number">1</span>],xlim = [-<span class="number">0.5</span>,<span class="number">2</span>],title = <span class="string">&#x27;&#x27;</span>)</span><br><span class="line">ax2.axis(<span class="string">&#x27;off&#x27;</span>)                                  <span class="comment">#边框消失</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#画柱2</span></span><br><span class="line"><span class="comment">#lll = [1.333,3.111,2.667,2.222,3.556,3.111,2.043,2.043,2.809,1.787,1.021,1.021,1.277]</span></span><br><span class="line">lll = [<span class="number">6.667</span>,<span class="number">6.667</span>,<span class="number">4.444</span>,<span class="number">2.222</span>,<span class="number">9.882</span>,<span class="number">6.588</span>,<span class="number">8.235</span>,<span class="number">3.294</span>,<span class="number">6</span>,<span class="number">18</span>]</span><br><span class="line"><span class="comment">#colorssss = [&#x27;#ffbd9d&#x27;,&#x27;#ff8f59&#x27;,&#x27;#ff5809&#x27;,&#x27;#ff5151&#x27;,&#x27;#ea0000&#x27;,&#x27;#ff5809&#x27;,&#x27;#d7ffee&#x27;</span></span><br><span class="line"><span class="comment">#             ,&#x27;#96fed1&#x27;,&#x27;#4efeb3&#x27;,&#x27;#02f78e&#x27;,&#x27;#28ff28&#x27;,&#x27;#00db00&#x27;,&#x27;#007500&#x27;]</span></span><br><span class="line">colorssss = [<span class="string">&#x27;#ffffaa&#x27;</span>,<span class="string">&#x27;#ffff6f&#x27;</span>,<span class="string">&#x27;#f9f900&#x27;</span>,<span class="string">&#x27;#d9b300&#x27;</span>,<span class="string">&#x27;#bbffff&#x27;</span>,<span class="string">&#x27;#80ffff&#x27;</span>,<span class="string">&#x27;#00e3e3&#x27;</span>,<span class="string">&#x27;#00aeae&#x27;</span>,<span class="string">&#x27;#ca8eef&#x27;</span>,<span class="string">&#x27;#d200d2&#x27;</span>]</span><br><span class="line">colorssss.reverse()</span><br><span class="line">lll.reverse()</span><br><span class="line"><span class="comment">#Z1 : Proportion of bachelor\&#x27;s degree education</span></span><br><span class="line">ttt = [<span class="string">&#x27;Proportion of bachelor\&#x27;s degree education&#x27;</span></span><br><span class="line">       ,<span class="string">&#x27;Registration rate of secondary school graduates&#x27;</span></span><br><span class="line">       ,<span class="string">&#x27;Graduation rate of College Students&#x27;</span></span><br><span class="line">       ,<span class="string">&#x27;Number of postgraduate examination&#x27;</span></span><br><span class="line">       ,<span class="string">&#x27;Education policy support&#x27;</span></span><br><span class="line">       ,<span class="string">&#x27;Teaching supervision system&#x27;</span></span><br><span class="line">       ,<span class="string">&#x27;Regional differences in teaching quality&#x27;</span></span><br><span class="line">       ,<span class="string">&#x27;Education supporting industry&#x27;</span></span><br><span class="line">       ,<span class="string">&#x27;Environmental driving role&#x27;</span></span><br><span class="line">       ,<span class="string">&#x27;People\&#x27;s cognitive attitude towards education&#x27;</span>]</span><br><span class="line"></span><br><span class="line">tttr = ttt.copy()</span><br><span class="line">tttr.reverse()</span><br><span class="line">rates = (np.array(lll)/<span class="built_in">sum</span>(lll)).tolist()</span><br><span class="line">posX =  <span class="number">1.7</span></span><br><span class="line">floor = <span class="number">0</span></span><br><span class="line">width = <span class="number">0.2</span></span><br></pre></td></tr></table></figure>
<p>​</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="built_in">len</span>(rates)):</span><br><span class="line">    height = rates[i]</span><br><span class="line">    ax0.bar(posX,height,width,bottom = floor,color = colorssss[i])</span><br><span class="line">    posY = ax0.patches[i].get_height() / <span class="number">2</span> + floor</span><br><span class="line">    ax0.text(posX+<span class="number">0.1</span>,posY,ttt[i]+<span class="string">&#x27;      %.2f%%&#x27;</span> % (lll[i]), ha = <span class="string">&#x27;right&#x27;</span>)</span><br><span class="line">    floor += ax0.patches[i].get_height()</span><br><span class="line"></span><br><span class="line">ax0.<span class="built_in">set</span>(ylim = [<span class="number">0</span>,<span class="number">1</span>],xlim = [-<span class="number">0.5</span>,<span class="number">2</span>],title = <span class="string">&#x27;&#x27;</span>)</span><br><span class="line">ax0.axis(<span class="string">&#x27;off&#x27;</span>)                                  <span class="comment">#边框消失</span></span><br><span class="line"><span class="comment">#ax1.legend(tttr,loc = &#x27;center&#x27;)</span></span><br><span class="line"></span><br><span class="line">ax1.set_title(<span class="string">&#x27;Weight of Every Factor&#x27;</span>,fontsize = <span class="number">30</span>)</span><br><span class="line">plt.savefig(<span class="string">&#x27;Weight of Every Factor.png&#x27;</span>)</span><br></pre></td></tr></table></figure>
<p>![在这里插入图片描述](<a target="_blank" rel="noopener" href="https://img-blog.csdnimg.cn/2021020913414042.png?x-oss-">https://img-blog.csdnimg.cn/2021020913414042.png?x-oss-</a><br />
process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dsZGNtenk=,size_16,color_FFFFFF,t_70#pic_center)</p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://example.com/1111/11/11/%E3%80%90%E5%AD%A6%E4%B9%A0%E8%AE%B0%E5%BD%95%E3%80%91python%20matplotlib%20%E8%87%AA%E5%AD%A6%E5%85%A5%E9%97%A8%EF%BC%88%E9%9A%8F%E7%BC%98%E6%9B%B4%E6%96%B0%EF%BC%89/" data-id="cl2uhoeca001qe4j32wc7aajp" class="article-share-link">分享</a>
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/OldBlog-Before20220505/" rel="tag">OldBlog(Before20220505)</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/python%E5%BA%93/" rel="tag">python库</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E7%94%BB%E5%9B%BE/" rel="tag">画图</a></li></ul>

    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/1111/11/11/%E3%80%90%E5%8C%BA%E9%97%B4DP%E7%BB%83%E4%B9%A0%E3%80%91%E6%B4%9B%E8%B0%B7%20P1880%5BNOI1995%5D%E7%9F%B3%E5%AD%90%E5%90%88%E5%B9%B6%20P1063%E8%83%BD%E9%87%8F%E9%A1%B9%E9%93%BEP2654%20%E5%8E%9F%E6%A0%B8%E7%94%9F%E7%89%A9%E5%9F%B9%E5%85%BB/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">上一篇</strong>
      <div class="article-nav-title">
        
          【区间DP练习】洛谷 P1880[NOI1995]石子合并 P1063能量项链P2654 原核生物培养.md
        
      </div>
    </a>
  
  
    <a href="/1111/11/11/%E3%80%90%E5%AD%A6%E4%B9%A0%E8%AE%B0%E5%BD%95%E3%80%91%E3%80%90Python%E3%80%91%E3%80%90numpy%E3%80%91%E8%87%AA%E5%AD%A6numpy%E5%BA%93%E7%9A%84%E7%AE%80%E8%A6%81%E8%AE%B0%E5%BD%95%E5%B8%96%EF%BC%88%E5%B7%B2%E7%BB%8F%E8%85%B0%E6%96%A9%E6%8D%A2%E6%96%B0%E7%9A%84%EF%BC%89/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">下一篇</strong>
      <div class="article-nav-title">【学习记录】【Python】【numpy】自学numpy库的简要记录帖（已经腰斩换新的）.md</div>
    </a>
  
</nav>

  
</article>



</section>
        
          <aside id="sidebar">
  
    <div class="widget-wrap">
  <h3 class="widget-title"></h3>
  <div class="widget">
    <h1 class="blog-title">蓝湖畔淅淅沥沥的雨</h1>
    <h2 class="blog-subtitle">All tragedy erased, I see only wonders...</h2>
    <ul class="blog-link">
     
          <a href="/" title="Home">
            <li>主页</li>
          </a>
        
          <a href="/archives" title="Archives">
            <li>归档</li>
          </a>
        
          <a href="/categories" title="Categories">
            <li>分类</li>
          </a>
        
          <a href="/tags" title="Tags">
            <li>标签</li>
          </a>
        
          <a href="/knightabout" title="Knightabout">
            <li>关于</li>
          </a>
        
          <a href="/bridges" title="Bridges">
            <li>传送门</li>
          </a>
        
          <a href="/announcement" title="Announcement">
            <li>公告</li>
          </a>
        
    </ul>
  </div>
</div>

  
    <div class="widget-wrap">
  <h3 class="widget-title"></h3>
  <div class="widget">
    <img class="avatar" src="/images/avatar.png">
    <h2 class="author">StarsWhisper</h2>
    <h3 class="description"></h3>
    <div class="count-box">
      <a href="/archives"><div><strong>75</strong><br>文章</div></a>
      <a href="/categories"><div><strong>31</strong><br>分类</div></a>
      <a href="/tags"><div><strong>56</strong><br>标签</div></a>
    </div>



    <div class="social-link">
      
        <a class="hvr-bounce-in" href="https://github.com/Wldcmzy" target="_blank" title="Github">
          Github
        </a>
      
        <a class="hvr-bounce-in" href="https://blog.csdn.net/wldcmzy" target="_blank" title="CSDN">
          CSDN
        </a>
      
        <a class="hvr-bounce-in" href="https://space.bilibili.com/83743701" target="_blank" title="bilibili(无技术和学习内容)">
          bilibili(无技术和学习内容)
        </a>
      
    </div>

    <div class="friend-link">
      <h2>友情链接</h2>
      
        <a class="hvr-bounce-in" href="https://shanamaid.github.io/" target="_blank" title="夏娜主题作者的博客">
          夏娜主题作者的博客
        </a>
      
    </div>
  </div>
</div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy;2021 - 2022 StarsWhisper<br>
      由<a href="http://hexo.io/" target="_blank">Hexo</a>强力驱动 | 
      主题-<a target="_blank" rel="noopener" href="https://github.com/ShanaMaid/hexo-theme-shana">Shana</a>(但是魔改)
      
    </div>
    
  </div>
</footer>
    </div>
    

<script src="//apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="//apps.bdimg.com/libs/wow/0.1.6/wow.min.js"></script>
<script>
new WOW().init();
</script>   


  
<link rel="stylesheet" href="/plugin/fancybox/jquery.fancybox.css">

  
<script src="/plugin/fancybox/jquery.fancybox.pack.js"></script>




  
<link rel="stylesheet" href="/plugin/galmenu/GalMenu.css">

  
<script src="/plugin/galmenu/GalMenu.js"></script>

  <div class="GalMenu GalDropDown">
      <div class="circle" id="gal">
        <div class="ring">
          
            <a href="/announcement" title="" class="menuItem">公告</a>
          
            <a href="/tags" title="" class="menuItem">标签</a>
          
            <a href="/categories" title="" class="menuItem">分类</a>
          
            <a href="/archives" title="" class="menuItem">归档</a>
          
            <a href="/knightabout" title="" class="menuItem">关于</a>
          
            <a href="/bridges" title="" class="menuItem">传送门</a>
          
        </div>
        
          <audio id="audio" src="#"></audio>
        
      </div> 
</div>
<div id="overlay" style="opacity: 1; cursor: pointer;"></div>
  <script type="text/javascript">var items = document.querySelectorAll('.menuItem');
    for (var i = 0,
    l = items.length; i < l; i++) {
      items[i].style.left = (50 - 35 * Math.cos( - 0.5 * Math.PI - 2 * (1 / l) * i * Math.PI)).toFixed(4) + "%";
      items[i].style.top = (50 + 35 * Math.sin( - 0.5 * Math.PI - 2 * (1 / l) * i * Math.PI)).toFixed(4) + "%"
    }</script>
<script type="text/javascript">
  $(document).ready(function() {
    $('body').GalMenu({
      'menu': 'GalDropDown'
    })
  });
</script>

  <section class="hidden-xs"> 
  <ul class="cb-slideshow"> 
    <li><span>苟利</span></li> 
    <li><span>国家</span></li> 
    <li><span>生死以</span></li> 
    <li><span>岂能</span></li> 
    <li><span>祸福</span></li> 
    <li><span>趋避之</span></li> 
  </ul>
</section>

<script src="/js/script.js"></script>




  </div>
</body>
</html>